package com.example.two.controller;

import com.example.two.domain.User;
import com.example.two.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    UserService userService;

    @GetMapping("/{id}")
    public User getUserById(@PathVariable Long id){
        return userService.getUserById(id);
    }

    @GetMapping
    public List<User> getAll(){
        return userService.getAll();
    }

    @PostMapping
    public boolean insert(@RequestBody User user){
        return userService.insert(user);
    }

    @PutMapping
    public boolean update(@RequestBody User user){
        return userService.update(user);
    }


    @DeleteMapping("{id}")
    public boolean delete(@PathVariable Long id){
        return userService.delete(id);
    }

    @GetMapping("/orders/{id}")
    public User getUserWithOrders(@PathVariable  Long id){
        return userService.getUserWithOrders(id);
    };

    @GetMapping("/ordercount")
    public List<Map<String, Object>> getUserOrderCount() {
        return userService.getUserOrderCount();
    }

    @GetMapping("/User-orders")
    public List<User> getUsersWithOrders() {
        return userService.getUsersWithOrders();
    }

    @GetMapping("/agegroup")
    public List<Map<String, Object>> getAgeGroupStatistics() {
        return userService.countUsersByAgeGroup();
    }

}
